package com.likeycy.my;


import com.likeycy.my.entity.Person;

import java.util.ArrayList;

/**
 * @ClassName: TestMyArrayList
 * @Description: 测试类
 * @Author: sodagreen
 * @Date: 2021/2/20 9:23
 * @Version: 1.0
 */
public class TestMyArrayList {

    public static void main(String[] args) {
        ArrayList<Person> arrayList = new ArrayList<>();
        arrayList.add(new Person("杰克", 18));
        arrayList.add(new Person("杰克", 19));
        int a = arrayList.indexOf(new Person("杰克", 19));
        boolean flag = arrayList.get(1).equals(new Person("杰克", 19));

        System.out.println(a);


        // 右移是除以2^n,左移是乘以2^次方
        // 8 << 1 = 8 * 2 = 16; 8 << 2 = 8 * 2 * 2 = 32
        System.out.println(8 << 1);
        System.out.println(8 << 2);
        // 8 >> 1 = 8 / 2 = 4; 8 >> 2 = 8 / 2 / 2 = 2
        System.out.println(8 >> 1);
        System.out.println(8 >> 2);


        /*testMyArrayList();
        testMyArrayListUpgradeFirstVersion();*/
        testMyArrayListUpgradeSecondVersion();
        testMyArrayListUpgradeSecondVersion2();
    }

    public static void testMyArrayList() {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(10);
        myArrayList.add(20);
        myArrayList.add(30);
        myArrayList.add(3, 100);
        Assert.test(myArrayList.get(3) == 100);

        int oldVlue = myArrayList.set(2, 50);
        Assert.test(oldVlue == 30);

        Assert.test(myArrayList.remove(1) == 20);
        System.out.println(myArrayList);
    }

    public static void testMyArrayListUpgradeFirstVersion() {
        MyArrayListUpgradeFirstVersion<Person> firstVersionList = new MyArrayListUpgradeFirstVersion<>();
        firstVersionList.add(new Person("杰克", 18));
        firstVersionList.add(null);
        firstVersionList.add(new Person("肉丝", 20));
        firstVersionList.add(null);
        firstVersionList.add(new Person("摩托车", 25));
        System.out.println(firstVersionList.indexOf(null));
        System.out.println(firstVersionList);
        firstVersionList.clear();
        System.out.println(firstVersionList);
        System.gc();
    }

    public static void testMyArrayListUpgradeSecondVersion() {
        MyArrayListUpgradeSecondVersion<Person> secondVersionList = new MyArrayListUpgradeSecondVersion<>();
        secondVersionList.add(new Person("杰克", 18));
        secondVersionList.add(new Person("杰克", 18));
        secondVersionList.add(null);
        secondVersionList.add(new Person("肉丝", 20));
        secondVersionList.add(null);
        secondVersionList.add(new Person("摩托车", 25));
        secondVersionList.remove(new Person("杰克", 18));
        System.out.println(secondVersionList);
        secondVersionList.remove(null);
        System.out.println(secondVersionList);
        System.out.println(secondVersionList.indexOf(null));
        System.out.println(secondVersionList);
    }

    public static void testMyArrayListUpgradeSecondVersion2() {
        MyArrayListUpgradeSecondVersion<Integer> secondList = new MyArrayListUpgradeSecondVersion<>();
        for (int i = 0; i < 50; i++) {
            secondList.add(i);
        }
        for (int i = 0; i < 50; i++) {
            secondList.remove(0);
        }
        System.out.println(secondList);

    }
}
